package com.dashboard.dkmh;

import java.util.ArrayList;
import java.util.HashMap;

import com.lb.jwitter.connectDatabase.ConnectPDT;
import com.opensymphony.xwork2.Action;

public class dkmhAction {
	private String jsonData;
	public String getJsonData() {
		return jsonData;
	}


	public void setJsonData(String jsonData) {
		this.jsonData = jsonData;
	}
	////////////////////////////////////////////////////////
	private String namHoc;

	public String getNamHoc() {
		return namHoc;
	}


	public void setNamHoc(String namHoc) {
		this.namHoc = namHoc;
	}
	/////////////////////////////////////////////////////////
	private String hocKy;

	public String getHocKy() {
		return hocKy;
	}


	public void setHocKy(String hocKy) {
		this.hocKy = hocKy;
	}
	/////////////////////////////////////////////////////////
	private String khoa;
	public String getKhoa() {
		return khoa;
	}


	public void setKhoa(String khoa) {
		this.khoa = khoa;
	}
	/////////////////////////////////////////////////////////
	private String boMon;

	public String getBoMon() {
		return boMon;
	}


	public void setBoMon(String boMon) {
		this.boMon = boMon;
	}

	

	public String execute() throws Exception
	{
		ConnectPDT connectionOracle= new ConnectPDT();
		if(connectionOracle.getConnection()!=null){
			//hocKy o day co gia tri 20142 : namHoc 2014 , hocKy 2
			/*
			if(namHoc==null||namHoc.length()<1){
				return Action.ERROR;
			}
			*/
			System.out.println("->get DKMH data");
			System.out.println("+hocKy : " + hocKy);
			System.out.println("+khoa : " + khoa);
			if(hocKy==null||hocKy.length()<1){
				System.out.println("@hocky error");
				return Action.ERROR;
			}
			if(khoa==null||khoa.length()<1){
				System.out.println("@khoa error");
				return Action.ERROR;
			}
			String semester=hocKy ; //namHoc+hocKy;
			String query="select count (*) as count,DKMH.MA_MH, DM_MON_HOC.TEN_MH"
					 +" from PDT_WEB.DKMH, PDT_WEB.DM_MON_HOC,(select MA_BO_MON, MA_KHOA  from PDT_WEB.DM_BO_MON where MA_KHOA='"+khoa+"') C"
					 +" where  DKMH.MA_MH=DM_MON_HOC.MA_MH and HK_NH ='"+semester+"' and DM_MON_HOC.MA_BO_MON=C.MA_BO_MON"
					 +" GROUP BY (DKMH.MA_MH, DM_MON_HOC.TEN_MH) "
					 +" order by count";
			jsonData=connectionOracle.getJSonData(query);
			
			System.out.println(jsonData);
			System.out.println("#get DKMH data");
		}
		
		connectionOracle.closeConnection();
		return Action.SUCCESS;

	}

}
